using System.Runtime.CompilerServices;
using Awaiter;
using Nsb.Classes;
using jQueryApi;

namespace WhirliGigEdit.Classes
{
    [IgnoreNamespace]
    public class Colorizer : Modifier
    {
        public const string ColorPickerKey = "ColorPickerTable";

        public Colorizer(ModOptions options) : base(options)
        {
            new Await()
                .LoadText(ColorPickerKey, Uri.Scripts("Data/GigColorPicker.html"))
                .AddDx(
                    delegate
                    {
                        Opts.HtmlString = ColorPickerTable();
                        Build("Colorizer");

                        jQueryObject opacity = OpacityEl()
                            ;

                        jQuery.Select(".Body", Element)
                            .Click(PickEv)
                            .Append(opacity)
                            ;
                    })
                .Commit();
        }

        public void PickEv(jQueryEvent e)
        {
            OnProp(jQuery.FromElement(e.Target).GetAttribute("title"));
        }

        private string ColorPickerTable()
        {
            string ot = "";
            ot += "<div class='Gads'>";
            ot += "<span title='none'>x</span>&nbsp;&nbsp;";
            ot += "<span title='transparent'>&#9744;</span>";
            ot += "</div>";
            ot += (string) Await.Files[ColorPickerKey];
            //ot += "<div class='Opaque'>Opaque <input type='text' size='2' class='" + colorName + "' value='" + (Css.AlphaPercent((string)MyCss[colorName]) ?? "") + "'>%</div>";
            return ot;
        }
    }
}